package january.test_1_19;

public class Solution {
    public int deleteAndEarn(int[] nums) {
        int[] arr = new int[20001];
        for(int i = 0; i < nums.length; i++) {
            arr[nums[i]] += nums[i];
        }
        int[] f= new int[20001];
        int[] g= new int[20001];
        f[0] = arr[0];
        for(int i = 1; i <= 20001; i++)
        {
            f[i] = g[i - 1] + arr[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        return Math.max(f[20000], g[20000]);
    }
}
